package net.llz.vo;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.math.BigDecimal;
import java.util.List;

public class CartVO {

    /**
     * 购物项
     */
    @JsonProperty("cart_items")
    private List<CartItemVO>cartItems;
    /**
     * 购物数量
     */
    @JsonProperty("total_num")
    private Integer totalNum;
    /**
     * 购物总价格
     */
    @JsonProperty("total_price")
    private BigDecimal totalPrice;
    /**
     * 支付价格
     */
    @JsonProperty("real_pay_price")
    private BigDecimal realPayPrice;

    /**
     * 总件数
     * @return
     */
    public Integer getTotalNum() {
        if (this.cartItems!=null){
            int total = cartItems.stream().mapToInt(CartItemVO::getBuyNum).sum();
            return total;
        }
        return 0;

    }

    /**
     * 总价格
     * @return
     */
    public BigDecimal getTotalPrice() {
        BigDecimal amount = new BigDecimal("0");

        if (this.cartItems!=null){
            for (CartItemVO cartItemVO : cartItems){
                BigDecimal itemTotalAmount=cartItemVO.getTotalAmount();
                amount = amount.add(itemTotalAmount);
            }
        }
        return amount;
    }

    /**
     * 购物车实际支付的价格
     * @return
     */
    public BigDecimal getRealPayPrice() {
        BigDecimal amount = new BigDecimal("0");

        if (this.cartItems!=null){
            for (CartItemVO cartItemVO : cartItems){
                BigDecimal itemTotalAmount=cartItemVO.getTotalAmount();
                amount = amount.add(itemTotalAmount);
            }
        }
        return amount;
    }

    public void setCartItems(List<CartItemVO> cartItems) {
        this.cartItems = cartItems;
    }

    public void setTotalNum(Integer totalNum) {
        this.totalNum = totalNum;
    }

    public void setTotalPrice(BigDecimal totalPrice) {
        this.totalPrice = totalPrice;
    }

    public void setRealPayPrice(BigDecimal realPayPrice) {
        this.realPayPrice = realPayPrice;
    }
}
